# -*- coding:UTF-8 -*-
"""
@Project : pythonProject
@File    : Multi_Threading1.py
@IDE     : PyCharm
@Author  : WorldWind(1772830365@qq.com)
@Address : China - HeiLongjiang - Herbin
@Date    : 2025/7/15 上午11:14
"""
from time import ctime, sleep
import threading
class Count:
    def __init__(self,i):
        self.i = i
        print(f'This is __init__ method. {self.get_class_name()} class startup')
        self.lock = threading.Lock()
    def add(self):
        for i in range(100000000):
            self.lock.acquire()
            self.i += 1
            self.lock.release()
    def sub(self):
        for i in range(100000000):
            self.lock.acquire()
            self.i -= 1
            self.lock.release()
    @classmethod
    def get_class_name(cls):
        return cls.__name__

    def __del__(self):
        print(f'This is __del__ method. The {self.get_class_name()} class has been recycled')

if __name__ == '__main__':
    c = Count(1)
    # c.add()
    # c.sub()
    # print(c.i)
    th1 = threading.Thread(target=c.add,args=())
    th2 = threading.Thread(target=c.sub,args=())
    th1.start()
    th2.start()
    th1.join()
    th2.join()
    print(c.i)
    print('The end!')

